<template>
  <div>
       <van-button
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            @click="follow"
            v-if="!isFollow"
            size="small"
            icon="plus"
          >关注</van-button>
          <van-button
            class="follow-btn"
            round
            v-else
            @click="follow"
            size="small"
          >已关注</van-button>
  </div>
</template>

<script>
import { userFollowAPI, deleteUserFollowAPI } from '@/api/article.js'
import { Toast } from 'vant'
export default {
  props: {
    isFollow: {
      type: Boolean,
      required: true
    },
    autID: {
      type: [Number, Object],
      required: true
    }

  },
  model: {
    prop: 'isFollow',
    event: 'updateisFollow'
  },
  methods: {
    // 点击关注或取消关注
    async follow () {
      try {
        if (!this.isFollow) {
          await userFollowAPI(this.autID)
          Toast.success('取消操作成功')
        } else {
          await deleteUserFollowAPI(this.autID)
          Toast.success('添加操作成功')
        }
        this.$emit('updateisFollow', !this.isFollow)
      } catch (error) {
        Toast.fail('操作失败')
      }
    }
  }
}
</script>

<style>

</style>
